<template>
  <div id='pickStock' class="pick-stock">
    <mt-header fixed title="万能选股器" v-if="isHeader">
      <mt-button icon="back" slot="left" @click="goBack"></mt-button>
      <mt-button icon="search" slot="right" @click="goSearch"></mt-button>
    </mt-header>
    <div class="pick-cont" :class="isHeader?'isHeader':''">
      <div class="pick-search" v-if="!isHeader" @click="goSearch">
        <div class="pick-search-inner">
          <i class="mintui mintui-search pick-search-icon"></i>
          <input ref="input" readonly type="search" placeholder="搜索因子" class="pick-search-input">
        </div>
      </div>
      <!--<mt-swipe class="pick-banner" :auto="5000" :prevent="true">-->
        <!--<mt-swipe-item v-for="s in bannerlist" :key="s.id">-->
          <!--<img :src="s.picUrl" alt="">-->
        <!--</mt-swipe-item>-->
      <!--</mt-swipe>-->
      <div class="pick-box" @click="goToHotNews">
        <div class="header-title">
          <span class="fl vertical-line"></span>
          <h2 class="fl top-title">热点资讯</h2>
          <!--<i class="fa fa-ellipsis-h go-btn" aria-hidden="true"></i>-->
          <span class="go-btn" aria-hidden="true">更多</span>
        </div>
        <div class="devide-line"></div>
        <div class="super-wave hot-new">
          <my-carousel :news="hotNews"></my-carousel>
        </div>
      </div>
      <div class="pick-box">
        <div class="header-title">
          <span class="fl vertical-line"></span>
          <h2 class="fl top-title">因子分类</h2>
          <!--<i class="fa fa-ellipsis-h go-btn" aria-hidden="true"></i>-->
        </div>
        <div class="devide-line"></div>
        <div class="super-wave factor-sort">
          <div class="sub-factor-type">
            <ul class="sub-factor-items">
              <li v-for="s in sorts" @click="goFactorSortsMore(s)">
                <span>{{s.cName}}</span>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="pick-box">
        <div class="header-title" @click="goFactorHotsMore">
          <span class="fl vertical-line"></span>
          <h2 class="fl top-title">热门因子</h2>
          <!--<i class="fa fa-ellipsis-h go-btn" aria-hidden="true"></i>-->
          <span class="go-btn" aria-hidden="true">更多</span>
        </div>
        <div class="devide-line"></div>
        <div class="super-wave factor_hots">
          <ul class="sub-factor-items">
            <li v-for="(h, index) in hotFactors" :key="index" @click="selectFactor(h)">
              <!--<span>{{h.factor_name}}</span>-->
              <span>{{h.factor_name}}</span>
            </li>
          </ul>
          <ul v-if="hotFactors.length<=0" class="sub-factor-items">
            暂无数据
          </ul>
        </div>
      </div>
      <div class="pick-box">
        <div class="header-title" @click="goFactorNewsMore">
          <span class="fl vertical-line"></span>
          <h2 class="fl top-title">最新因子</h2>
          <!--<i class="fa fa-ellipsis-h go-btn" aria-hidden="true"></i>-->
          <span class="go-btn" aria-hidden="true">更多</span>
        </div>
        <div class="devide-line"></div>
        <div class="super-wave factor_news">
          <ul class="sub-factor-items">
            <li v-for="n in newFactors" @click="selectFactor(n)">
              <span>{{n.factor_name}}</span>
            </li>
          </ul>
          <ul v-if="newFactors.length<=0" class="sub-factor-items">
            暂无数据
          </ul>
        </div>
      </div>
      <div class="pick-box">
        <div class="header-title" @click="goMyStrategyMore">
          <span class="fl vertical-line"></span>
          <h2 class="fl top-title">我的策略</h2>
          <!--<i class="fa fa-ellipsis-h go-btn" aria-hidden="true" @click="goMyStrategyMore"></i>-->
          <span class="go-btn" aria-hidden="true">更多</span>
        </div>
      </div>
      <div class="devide-line"></div>
      <p class="pick-dec">● 免责声明:万能选股基于市场公开信息及股票信号识别聚合而成,不构成具体投资建议,请确保已完全理解其实际含义,避免因误解而导致与您的预期不一致,股市有风险,入市需谨慎.</p>
    </div>
    <!--<mt-button type="default" class="myStrategy-btn" @click="">我的策略</mt-button>-->
  </div>
</template>

<script>
  import REQUEST from './../services/test'
  import {formatDate} from './../utility/date'

  export default {
    components: {},
    name: 'pickStock',
    data () {
      return {
        isHeader: false,
        bannerlist: [
          {picUrl: './static/img/banner01.png'}
        ],
        hotNews: [],
        newFactors: [],
        hotFactors: [],
        sorts: [
          {
            cName: '概念因子',
            type: 'concept'
          },
          {
            cName: '技术因子',
            type: 'tech'
          },
          {
            cName: '财务因子',
            type: 'finance'
          },
          {
            cName: '行业因子',
            type: 'industry'
          },
          {
            cName: '风格因子',
            type: 'style'
          },
          {
            cName: '地域因子',
            type: 'district'
          }
        ]
      }
    },
    created () {
      this.$store.commit('getUrlParams')
      this.isHeader = this.$store.state.isHeader
      this.$store.dispatch('isAllFactors')
      this.getHotNew()
      this.getNewFactor()
      this.getHotFactor()
    },
    beforeMount () {
    },
    mounted () {
//      this.getBanner()
    },
    methods: {
      goBack: function () {
        // history.go(-1)
        // this.$router.go(-1)
        this.$router.replace('/home')
      },
      goSearch () {
        this.$router.push('/search')
      },
      goToHotNews () {
        this.$router.push('/hotNew')
      },
      goFactorSortsMore (s) {
        this.$router.push({name: 'factorSortsMore', query: {type: s.type}})
      },
      goFactorNewsMore () {
        this.$router.push('/factorNewsMore')
      },
      goFactorHotsMore () {
        this.$router.push('/factorHotsMore')
      },
      goMyStrategyMore () {
        this.$router.push('/myStrategyMore')
      },
      // 获取banner图片
      getBanner () {
        REQUEST.getBanner().then(res => {
          this.bannerlist = res.result.banner_image
        }).catch(err => {
          console.info(err)
        })
      },
      // 获取热点资讯  前5个
      getHotNew () {
        let _self = this
        let _time = formatDate(new Date(), 'yyyy-MM-dd')
        let _url = '/' + _time + '/1'
        REQUEST.getHotNews(_url).then(res => {
          _self.hotNews = res.filter((v, k) => {
            return k < 2
          })
        })
      },
      // 获取最新因子  前6个
      getNewFactor () {
        let _self = this
        REQUEST.getNewFactor().then(res => {
          // console.log('重新请求--------newFactors', res)
          let _arr = []
          if (res.data.length > 0) {
            res.data.forEach(v => {
              _arr.push(v.factor_id)
            })
          }
          let _allFactors = _self.$store.state.allFactors
          let _factorId = _arr.join('|')
          _self.newFactors = _allFactors.filter(v => {
            return _factorId.indexOf(v.factor_id) > -1
          }).filter((v, k) => {
            return k < 6
          })
          _self.$store.state.newFactors = res.data
        })
      },
      // 获取热门因子  前6个
      getHotFactor () {
        let _self = this
        REQUEST.getHotFactor(20, 2).then(res => {
          // console.log('重新请求--------hotFactors', res)
          let _arr = []
          if (res.length > 0) {
            res.forEach(v => {
              _arr.push(v.factor_id)
            })
          }
          let _allFactors = _self.$store.state.allFactors
          let _factorId = _arr.join('|')
          _self.hotFactors = _allFactors.filter(v => {
            return _factorId.indexOf(v.factor_id) > -1
          }).filter((v, k) => {
            return k < 6
          })
          _self.$store.state.hotFactors = res
        })
      },
      // 选中或未选中因子状态
      selectFactor: function (_item) {
        _item.isSelect = !_item.isSelect
        if (_item.isSelect) {
          this.addFactor(_item)
        } else {
          this.delFactor(_item)
        }
      },
      // 添加因子
      addFactor (_item) {
        this.$store.commit('clearSelectFactor')
        this.$store.commit('pushSelectFactor', _item)
        this.$router.push({name: 'factorSortsMore', query: {type: _item.factor_type}})
      }
    },
    computed: {
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
  #pickStock {
    background: #f8f8f8;
    .mint-header.is-fixed {
      background-color: #0f1316;
      z-index: 99;
    }
    .pick-cont.isHeader {
      margin-top: 1.25rem !important;
    }
    .pick-cont {
      /*margin-top: 1.25rem;*/
      /*margin-bottom: 1.25rem;*/
      .pick-search {
        position: relative;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-box-align: center;
        -webkit-align-items: center;
        -moz-align-items: center;
        -ms-align-items: center;
        -o-align-items: center;
        align-items: center;
        background-color: #f2f2f2;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        display: box;
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        padding: 0.16rem 0.16rem;
        z-index: 1;
        .pick-search-inner {
          -webkit-box-align: center;
          -webkit-align-items: center;
          -moz-align-items: center;
          -ms-align-items: center;
          -o-align-items: center;
          align-items: center;
          background-color: #fff;
          border-radius: 0.0533333rem;
          display: box;
          display: -webkit-box;
          display: -moz-box;
          display: -ms-flexbox;
          display: -webkit-flex;
          display: flex;
          -webkit-box-flex: 1;
          -moz-box-flex: 1;
          /*width: 20%;*/
          -webkit-flex: 1;
          -ms-flex: 1;
          flex: 1;
          height: 0.7466667rem;
          padding: 0.1066667rem 0.16rem;
          .pick-search-icon {
            font-family: "mintui" !important;
            font-size: 0.4266667rem;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -webkit-text-stroke-width: 0.00533333rem;
          }
          .pick-search-input {
            text-indent: 0.16rem;
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
            border: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            outline: 0;
          }
        }
      }
      .pick-banner {
        height: 3.1733333rem;
        img {
          border: 0;
          height: 100%;
          width: 100%;
        }
      }
      .pick-box {
        margin-top: 0.2666667rem;
        .header-title {
          height: 1.0666667rem;
          line-height: 1.0666667rem;
          background: #ffffff;
          overflow: hidden;
          .vertical-line {
            display: inline-block;
            width: 0.08rem;
            height: 0.5333333rem;
            /*line-height: 1.0666667rem;*/
            position: relative;
            top: 50%;
            margin-top: -0.2666667rem;
            background-color: #3796e3;
          }
          .top-title {
            position: relative;
            left: 0.4rem;;
            top: 50%;
            margin-top: -0.5333333rem;
            font-weight: 600;
            font-size: 0.4rem;
            height: 1.0666667rem;
            overflow: hidden;
            /*line-height: 1.25rem;*/
            color: #000000;
          }
          .go-btn {
            float: right;
            height: 1.0666667rem;
            line-height: 1.0666667rem;
            font-size: 0.3733333rem;
            color: #1296db;
            padding-right: 0.4rem;
          }
        }
        .super-wave {
          height: 2.1333333rem;
          background: #ffffff;
          color: #000000;
          font-size: 0.3466667rem;
          position: relative;
          img {
            width: 9.1875rem;
            height: 2.34375rem;
          }
        }
        .super-wave.hot-new {
          overflow: hidden;
          min-height: 3.2rem;
          .swiper-box {
            z-index: 99999;
          }
        }
        .super-wave.factor-sort {
          height: auto;
          overflow: hidden;
          background: #ffffff;
          .sub-factor-type {
            height: inherit;
            .sub-factor-items {
              height: inherit;
              padding: 0.2rem;
              li {
                width: 33.3333333%;
                float: left;
                color: #000000;
                span {
                  height: 1.6266667rem;
                  line-height: 1.6266667rem;
                  display: block;
                  border: 0;
                  margin: 0.2rem;
                  font-size: 0.4533333rem;
                  text-indent: 0.8533333rem;
                }
                &:nth-of-type(1) {
                  span {
                    background: url('../../static/img/icon-gnyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
                &:nth-of-type(2) {
                  span {
                    background: url('../../static/img/icon-jsyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
                &:nth-of-type(3) {
                  span {
                    background: url('../../static/img/icon-dyyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
                &:nth-of-type(4) {
                  span {
                    background: url('../../static/img/icon-hyyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
                &:nth-of-type(5) {
                  span {
                    background: url('../../static/img/icon-fgyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
                &:nth-of-type(6) {
                  span {
                    background: url('../../static/img/icon-cwyz.png') no-repeat center center;
                    background-size: 100% 100%;
                  }
                }
              }
            }
          }
        }
        .super-wave.factor_news {
          height: auto;
          overflow: hidden;
          background: #ffffff;
          .sub-factor-items {
            height: inherit;
            padding: 0.2rem;
            li {
              float: left;
              width: 33.3333333%;
              color: #000000;
              span {
                height: 0.6666667rem;
                line-height: 0.6666667rem;
                background: #f8f8f8;
                display: block;
                margin: 0.2rem;
                font-size: 0.3466667rem;
                border-radius: 0.0533333rem;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }
            }
          }
        }
        .super-wave.factor_hots {
          height: auto;
          overflow: hidden;
          background: #ffffff;
          .sub-factor-items {
            height: inherit;
            padding: 0.2rem;
            li {
              float: left;
              width: 33.3333333%;
              color: #000000;
              span {
                height: 0.6666667rem;
                line-height: 0.6666667rem;
                background: #f8f8f8;
                display: block;
                margin: 0.2rem;
                font-size: 0.3466667rem;
                border-radius: 0.0533333rem;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }
            }
          }
        }
      }
      .pick-dec {
        padding: 0.265625rem 0.40625rem;
        background-color: #f7f7f7;
        color: #999999;
        text-align: left;
      }
      .devide-line {
        width: 100%;
        height: 0.0266667rem;
        background-color: #dddddd;
        border-bottom: 1px solid #f7f7f7;
      }
    }
  }

  /*底部我的策略按钮*/
  .myStrategy-btn {
    position: fixed;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    border-radius: 0;
    height: 1.25rem;
    color: #af2434;
    background-color: #fff;
  }
</style>
